// KillRun.cpp : Defines the entry point for the application.
//

#include "stdafx.h"

#include <shlwapi.h>
#include <tlhelp32.h>
#include <process.h>

#include <Mmsystem.h>
#include <commctrl.h>

#include "Toolhelp.h"


BOOL Proc_kill(char *SzName);

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
    CToolhelp::EnablePrivilege(SE_DEBUG_NAME, TRUE);
    CToolhelp::EnablePrivilege(SE_SECURITY_NAME, TRUE);

	Proc_kill("rundll32.exe");
	// Initialize global strings
	MessageBox(NULL, "Kill rundll32.exe success", "Kill success", MB_OK);
	return 0;

}


BOOL Proc_kill(char *SzName)
{
	HANDLE hProcessSnap;
	PROCESSENTRY32 pe32;

	hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
	pe32.dwSize = sizeof(PROCESSENTRY32);

	if (!Process32First(hProcessSnap, &pe32))
	{
		CloseHandle(hProcessSnap);
		return 0;
	}

	HANDLE hProcess;
	do
	{
		if ( strcmp(pe32.szExeFile,SzName)==0)
		{
			hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
			//GetExitCodeProcess(hProcess, &lpExitCode );
			//TerminateProcess(hProcess,lpExitCode);
			TerminateProcess(hProcess,0);
		}
	}
	while (Process32Next(hProcessSnap, &pe32));

	CloseHandle(hProcessSnap);
	return 0;	
}

